package com.zztl.infiniteBand.net


import android.content.Context

import com.zztl.infiniteBand.model.BaseResponseBean

import rx.Subscriber

/**
 * @desc
 * @auth ${user
 * @time 2018/6/4  14:17
 */
abstract class FilterSubscriber2<T>(internal var mContext: Context?) : Subscriber<T>() {

    override fun onStart() {
       start()

    }

    override fun onCompleted() {
        completed()
    }

    override fun onError(e: Throwable) {

        fail(e.message)
        if (e is Exception) {

        } else {
        }
    }

    override fun onNext(t: T) {

        if (t is BaseResponseBean<*>) {
            val bean = t as BaseResponseBean<*>
            if (bean.code != BaseResponseBean.OK) {
                //                ToastUtils.show(mContext,bean.getMessage() );
                fail(bean.message)
            } else {
                success(t)
            }
        }
    }

    protected abstract fun success(t: T)

    protected abstract fun fail(message: String?)
    protected fun completed() {}
    protected fun start() {}

}
